/**
  ******************************************************************************
* @file				bsp_tim.c
* @Software			MDK V5
* @Target 			MM32F5330
* @author			ou_teki
* @date				2024-0420
  ******************************************************************************
  */


#include	"bsp_tim.h"



uint8_t BSP_Tim6Init(void)
{
    NVIC_InitTypeDef        nvic_init_s;
    TIM_TimeBaseInitTypeDef tim_base_s;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);

    tim_base_s.TIM_Prescaler         = (TIM_GetTIMxClock(TIM6) / 1000000 - 1);
    tim_base_s.TIM_CounterMode       = TIM_CounterMode_Up;
    tim_base_s.TIM_Period            = (1000 - 1);
    tim_base_s.TIM_ClockDivision     = TIM_CKD_Div1;
    tim_base_s.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM6, &tim_base_s);

    TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);

    nvic_init_s.NVIC_IRQChannel = TIM6_IRQn;
    nvic_init_s.NVIC_IRQChannelPreemptionPriority = 0;
    nvic_init_s.NVIC_IRQChannelSubPriority = 1;
    nvic_init_s.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvic_init_s);

    TIM_Cmd(TIM6, ENABLE);

    return 0;
}



static uint16_t tim6_num = 0;
/***********************************************************************************************************************
  * @brief  This function handles TIM6 Handler
  * @note   none
  * @param  none
  * @retval none
  *********************************************************************************************************************/
void TIM6_IRQHandler(void)
{

    if (RESET != TIM_GetITStatus(TIM6, TIM_IT_Update))
    {
        TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
	
        tim6_num++;
        if(tim6_num == 500)
        {
            LED2_OFF();
        }
        if(tim6_num >= 1000)
        {
            tim6_num = 0;
            LED2_ON();
        }

    }
}












/********************************End of File************************************/

